package com.esun.common.mq.rabbitmq.producer;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.esun.common.log.DatabaseLogEo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 创建数据库日志消息
 * @author John.xiao
 * @date 2021/10/12 14:27
 */
@Component
@Slf4j
public class DatabaseLogProducer {
	@Resource
	AmqpTemplate amqpTemplate;

	public void sendLog(DatabaseLogEo databaseLog){
		String context  = JSONObject.toJSONString(databaseLog);
		log.info("sending database log :{}", JSONObject.toJSONString(context, SerializerFeature.PrettyFormat));
		amqpTemplate.convertAndSend("databaseLog",context);
	}
}
